﻿using System.Windows;
using System.Windows.Input;

namespace MetroWPF.Windows
{
    /// <summary>
    /// Provides a set of extenstion methods to get the commands in a window.
    /// </summary>
    internal static class WindowCommandsExtenstion
    {
        /// <summary>
        /// Gets the close command.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <returns></returns>
        internal static ICommand GetCloseCommand(this Window window)
        {
            return new WindowCommand(
                () => { window.Close(); },
                () => { return window.IsCloseButtonEnabled; }
                );
        }

        /// <summary>
        /// Gets the maximize command.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <returns></returns>
        internal static ICommand GetMaximizeCommand(this Window window)
        {
            return new WindowCommand(
                () =>
                {
                    //The action depends on the window state.
                    if (window.WindowState == WindowState.Maximized)
                    {
                        window.WindowState = WindowState.Normal;
                    }
                    else
                    {
                        window.WindowState = WindowState.Maximized;
                    }
                },
                () => { return window.IsMaximizeButtonEnabled; }
                );
        }

        /// <summary>
        /// Gets the minimize command.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <returns></returns>
        internal static ICommand GetMinimizeCommand(this Window window)
        {
            return new WindowCommand(
                () => { window.WindowState = WindowState.Minimized; },
                () => { return window.IsMinimizeButtonEnabled; }
                );
        }
    }
}